package com.hos.net.req.art;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.hos.net.req.BaseReq;
import com.hos.net.res.MsgHint;
import com.hos.utile.StringUtile;

/**
 * 更新文章
 * Created by guom on 2018/10/27.
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class ArtStateReq extends BaseReq {
    //文章id
    public String artId;
    //状态 1：审核状态 2：审核通过状态
    public String state;
    //状态 1:上架 2：下架
    public String issue;
    @JsonIgnore
    public String hint;

    // (false 检验失败)
    @JsonIgnore
    public boolean isVerifyParameter() {
        if (StringUtile.isEmpty(artId)) {
            hint = new MsgHint("文章id不能为空").toJson();
            return false;
        }
        if (state != null && !isValue(state)) {

            hint = new MsgHint("文章状态设置错误").toJson();
            return false;
        }
        if (issue != null && !isValue(issue)) {
            hint = new MsgHint("文章状态设置错误").toJson();
            return false;
        }
        if (state == null && issue == null) {
            hint = new MsgHint("文章状态不能为空").toJson();
            return false;
        }
        return true;
    }

    private boolean isValue(String value) {
        boolean isValid = false;
        switch (value) {
            case "1":
                isValid = true;
                break;
            case "2":
                isValid = true;
                break;
        }
        return isValid;
    }
}
